       import axios from 'axios'
       import render from 'art-template'

       // 读取query参数指定参数名的值
       function getQueryValue(name) {
           var str = location.href.split('?');
           var query = str[1];
           var vars = query.split('&');
           for (var i = 0; i < vars.length; i++) {
               var pair = vars[i].split("=");
               if (pair[0] == name) {
                   return pair[1];
               }
           }
           return (false);
       }
       // render函数
       const rende = async () => {
           const {
               data: res
           } = await axios(`http://localhost:8080/book/${getQueryValue('id')}`)
           const {
               data: book
           } = res
           const html = rende({
               book
           })
           document.querySelector('form').innerHTML = html
       }

       // 点击提交按钮发起请求跳转页面
       document.querySelector('#btn').onclick = async () => {
           // 收集数据
           const _id = document.getElementById('_id').value
           const name = document.getElementById('name').value
           const author = document.getElementById('author').value
           const price = document.getElementById('price').value

           // 发起请求
           const {
               data: res
           } = await axios.put('http://localhost:8080/book', {
               _id,
               name,
               author,
               price
           })
           if (res.code !== 200) return alert(res.message)
           alert(res.message)
           window.location = './list.html'
       }

       // 界面一显示就执行函数
       render()